package com.jie.study

import android.os.Bundle
import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.RecyclerView
import com.jie.commonlib.base.BaseActivity
import com.jie.commonlib.support.arouter.ARouterActivity
import com.jie.commonlib.support.arouter.ARouterManager
import com.jie.commonlib.support.arouter.ARouterParamKey
import com.jie.study.bean.MainBean

/**
 * demo主界面
 * @author jie
 */
class MainActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initToolbar()
        initView()
    }

    private fun initToolbar() {
        val toolbar = findViewById<Toolbar>(R.id.toolbar)
        toolbar.setTitle(R.string.app_name)
        setSupportActionBar(toolbar)
    }

    private fun initView() {
        val rvMain = findViewById<RecyclerView>(R.id.rvContent)
        rvMain.adapter = MainAdapter(initList()).apply {
            setOnItemClickListener { _, _, position ->
                val mainBean = data[position]
                ARouterManager.getInstance()
                    .openActivity(
                        this@MainActivity,
                        mainBean.activityPath,
                        Bundle().apply {
                            putBoolean(ARouterParamKey.PARAM_FROM_APP, true)
                        }
                    )
            }
        }
    }

    private fun initList(): ArrayList<MainBean> {
        val list = ArrayList<MainBean>()
        list.add(MainBean("常用算法", ARouterActivity.ACTIVITY_ALGORITHM))
        list.add(MainBean("学习测试", ARouterActivity.ACTIVITY_OTHER_HOME))
        list.add(MainBean("扫描二维码", ARouterActivity.ACTIVITY_QR_CODE_VIEW))
        return list
    }

}